<!DOCTYPE html>
<html>

<head>
    <title>抖音小助手</title>
    <meta charset="utf-8">
    <meta name="keywords" content="" />
    <meta name="description" content="" />
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="static/weui.min.css" media="all">
    <link rel="stylesheet" href="static/jquery-weui.min.css">
    <link rel="stylesheet" href="iconfont/iconfont.css" media="all">
    <style>
        [v-cloak] {
            visibility: hidden !important;
        }

        * {
            -webkit-touch-callout: none;
            -ms-touch-callout: none;
            -webkit-user-select: none;
            -moz-user-select: none;
            -ms-user-select: none;
            user-select: none;
        }

        body,
        html {
            color: #666666;
            width: 100%;
            height: 100%;
            margin: 0;
            padding: 0;
            font-size: 14px;
            background-color: #f5f5f5;
            font-family: Roboto, -apple-system, BlinkMacSystemFont, "Helvetica Neue", "Segoe UI", "Oxygen", "Ubuntu", "Cantarell", "Open Sans", sans-serif;
        }

        input[type=button],
        input[type=submit],
        input[type=text],
        input[type=password] {
            -webkit-appearance: none;
            outline: none
        }

        img {
            pointer-events: none;
        }

        .radius-3 {
            -webkit-border-radius: 3px;
            -moz-border-radius: 3px;
            border-radius: 3px;
        }

        .radius-5 {
            -webkit-border-radius: 5px;
            -moz-border-radius: 5px;
            border-radius: 5px;
        }

        ::-webkit-scrollbar {
            width: 5px;
            /*对垂直流动条有效*/
            height: 5px;
            /*对水平流动条有效*/
        }

        /*定义滚动条的轨道颜色、内阴影及圆角*/

        ::-webkit-scrollbar-track {
            background-color: rgba(255, 255, 255, 0.1);
            border-radius: 5px;
        }

        /*定义滑块颜色、内阴影及圆角*/

        ::-webkit-scrollbar-thumb {
            border-radius: 5px;
            background-color: rgba(255, 255, 255, 0.5);
        }

        /*定义两端按钮的样式*/

        ::-webkit-scrollbar-button {
            background-color: transparent;
        }

        /*定义右下角汇合处的样式*/

        ::-webkit-scrollbar-corner {
            background: transparent;
        }

        .VUE_BOX {
            padding: 10px 20px;
        }

        .version {
            font-size: 12px;
            color: #666;
            cursor: pointer;
            margin-left: 10px;
            font-weight: 400;
        }

        .title {
            margin-top: 20px;
            font-size: 16px;
        }

        .product {
            -webkit-app-region: drag;
            color: #111;
            /* padding-top: 30px; */
        }

        .intro {
            color: #333333;
            border-bottom: 3px solid #aaaaaa;
            padding-bottom: 5px;
        }

        .itembox {
            margin-top: 20px;
            color: #999;
        }

        .btnbox {
            -webkit-app-region: drag;
            float: right;
            margin-right: 5px;
            margin-top: 10px;
        }

        .btn {
            background-color: darkgreen;
            color: white;
            padding: 8px 20px;
            font-size: 14px;
            border: none;
            outline: none;
            cursor: pointer;
            border-radius: 5px;
        }

        .ctrlbox {
            margin-top: 10px;
        }

        .ctrl {
            background-color: #aaa;
            color: white;
            padding: 2px;
            cursor: pointer;
            font-size: 14px;
            border-radius: 3px;
            padding: 3px;
            margin-right: 5px;
        }

        .ctrl::before {
            margin-right: 3px;
        }

        .open {
            background-color: #333;
        }
    </style>
</head>

<body>
    <div class="VUE_BOX" v-cloak>
        <div class="btnbox">
            <block v-if="status.isRunning">
                <input class="btn" type="button" value="点击结束" onclick="end()" style="background-color:darkgreen" />
            </block>
            <block v-if="!status.isRunning">
                <input class="btn" type="button" value="点击开始" onclick="start()" style="background-color:#999" />
            </block>
        </div>
        <h1 class="product">抖音小助手<a href="javascript:version();" title="查看更新" class="version">V1.0.0</a></h1>
        <div class="title">
            <span class="intro">使用说明</span>
        </div>
        <div class="itembox">
            <div class="item">
                1. 安装Android手机对应系统的驱动，将手机USB连接至电脑；
            </div>
            <div class="item">
                2. 打开抖音APP，打开对应的粉丝列表，打开本应用；
            </div>
            <div class="item">
                3. 点击开始，任务即将自动开始，如需结束，请点击结束按钮；
            </div>
        </div>
        <div class="ctrlbox">
            <div id="followPercent" class="weui-slider" style="padding:0;margin-top:10px;">
                <div>关注概率：{{config.followPercent}}%</div>
                <div class="weui-slider__inner">
                    <div style="width: 90%;" class="weui-slider__track"></div>
                    <div style="left: 90%;" class="weui-slider__handler"></div>
                </div>
            </div>
            <div id="readPercent" class="weui-slider" style="padding:0;margin-top:10px;">
                <div>阅读概率：{{config.readPercent}}%</div>
                <div class="weui-slider__inner">
                    <div style="width: 90%;" class="weui-slider__track"></div>
                    <div style="left: 90%;" class="weui-slider__handler"></div>
                </div>
            </div>
            <div id="likePercent" class="weui-slider" style="padding:0;margin-top:10px;">
                <div>点赞概率：{{config.likePercent}}%</div>
                <div class="weui-slider__inner">
                    <div style="width: 70%;" class="weui-slider__track"></div>
                    <div style="left: 70%;" class="weui-slider__handler"></div>
                </div>
            </div>
            <div id="commentPercent" class="weui-slider" style="padding:0;margin-top:10px;">
                <div>评论概率：{{config.commentPercent}}%</div>
                <div class="weui-slider__inner">
                    <div style="width: 50%;" class="weui-slider__track"></div>
                    <div style="left: 50%;" class="weui-slider__handler"></div>
                </div>
            </div>
        </div>
    </div>
    <script src="static/jquery.min.js"></script>
    <script src="static/jquery-weui.min.js"></script>
    <script src="static/xml2json.min.js"></script>
    <script src="static/vue.js"></script>
    <script>
        var videoJson = {};
        var layJson = {};
        var profileJson = {};
        var exec = require('child_process').execSync;
        var fs = require('fs'); // 引入fs模块
        var { remote } = require('electron');
        var commentList = [];
        var commentsText = fs.readFileSync("./comments.txt", 'utf-8');
        var __temparr = commentsText.split("\n");
        for (var i = 0; i < __temparr.length; i++) {
            if (__temparr[i].length > 3) {
                commentList.push(__temparr[i]);
            }
        }
        function msgBox(content, title = '温馨提示') {
            remote.dialog.showErrorBox(title, content);
        }
        var VUE_APP = new Vue({
            el: ".VUE_BOX",
            data: {
                config: {
                    followPercent: 90,
                    readPercent: 90,
                    likePercent: 70,
                    commentPercent: 50,
                },
                status: {
                    isRunning: false
                }
            },
            created: function () {

            },
            mounted: function () {
                $('#followPercent').slider(function (percent) {
                    VUE_APP.config.followPercent = percent;
                })
                $('#readPercent').slider(function (percent) {
                    VUE_APP.config.readPercent = percent;
                })
                $('#likePercent').slider(function (percent) {
                    VUE_APP.config.likePercent = percent;
                })
                $('#commentPercent').slider(function (percent) {
                    VUE_APP.config.commentPercent = percent;
                })
            },
            methods: {
            }
        });
        function start() {
            echo("任务已开始");
            VUE_APP.status.isRunning = true;
            setTimeout(() => {
                getFansList();

            }, 100);
        }
        function end() {
            VUE_APP.status.isRunning = false;
        }
        var Global_fansHeadList = [];
        function getFansList() {
            echo("正在获取粉丝列表");
            layJson = getThePageLayout();
            Global_fansHeadList = getFansHeadPostionList(layJson);
            if (Global_fansHeadList.length == 0) {
                msgBox("你确定你打开了抖音的粉丝页？!", "运行失败");
                VUE_APP.status.isRunning = false;
                return;
            }
            echo("粉丝列表获取成功");
            openProfileTask();
        }
        function scollNextPage() {
            var _temp = JSON.stringify(layJson).match(/"_bounds":"\[0,0\](.*?)"/);
            var locationArray = ("[0,0]," + _temp[1]).match(/[\d]+/g);
            nowIndex = 0;
            console.log(locationArray);
            var x = parseInt((locationArray[2] - locationArray[0]) / 2);
            exec("adb shell input swipe " + x + " " + (locationArray[3] - 200) + " " + x + " " + (locationArray[1] + 500) + " 1000");
            setTimeout(() => {
                echo("滑动到下一页");
                getFansList();
            }, 3000);
        }
        var nowIndex = 0;
        function openProfileTask() {
            //打开用户页面
            if (VUE_APP.status.isRunning) {
                if (nowIndex + 1 > Global_fansHeadList.length) {
                    //本次已经完了 
                    echo("本页已打开完毕");
                    scollNextPage();
                    return;
                }
                var _fans = Global_fansHeadList[nowIndex];
                exec("adb shell input tap " + _fans.x + " " + _fans.y);
                setTimeout(() => {
                    //打开个人主页后等待3000加载
                    profileJson = getThePageLayout();
                    echo("个人主页加载完成");
                    if (parseInt(Math.random() * 100) < VUE_APP.config.readPercent) {
                        var videoTitleText = getProfileTabbarVideoText(profileJson);
                        var likeTitleText = getProfileTabbarLikeText(profileJson);
                        if (videoTitleText && videoTitleText != "作品 0" && videoTitleText != "作品") {
                            //用户自己发布过视频
                            echo("开始看用户发布的视频");
                            maxVideoReadCount = 1 + parseInt(Math.random() * 3);
                            var _location = getProfileTabbarVideo(profileJson);
                            if (!_location) {
                                //没有获取到Tabbar
                                if (parseInt(Math.random() * 100) < VUE_APP.config.followPercent) {
                                    var _location = getFollowButton(profileJson);
                                    if (_location) {
                                        echo("正在关注当前用户");
                                        exec("adb shell input tap " + _location.x + " " + _location.y);
                                    }
                                }
                                echo("正在返回列表");
                                exec("adb shell input keyevent 4");
                                nowIndex++;
                                setTimeout(() => {
                                    openProfileTask();
                                }, 2000);
                                return;
                            }
                            //先切换到作品tabbar
                            exec("adb shell input tap " + _location.x + " " + _location.y);
                            setTimeout(() => {
                                //往下100 点视频 播放
                                exec("adb shell input tap " + _location.x + " " + (_location.y + 100));
                                hasBeenReadedCount = 1;
                                echo("正在看第" + hasBeenReadedCount + "个作品");
                                //开始播放视频
                                playNextVideo(() => {
                                    echo("所有作品查看完毕");
                                    exec("adb shell input keyevent 4");
                                    echo("返回个人主页");
                                    setTimeout(() => {
                                        if (parseInt(Math.random() * 100) < VUE_APP.config.followPercent) {
                                            var _location = getFollowButton(profileJson);
                                            if (_location) {
                                                echo("正在关注当前用户");
                                                exec("adb shell input tap " + _location.x + " " + _location.y);
                                            }
                                        }
                                        echo("正在返回列表");
                                        exec("adb shell input keyevent 4");
                                        nowIndex++;
                                        setTimeout(() => {
                                            openProfileTask();
                                        }, 2000);
                                    }, 1000);
                                });
                            }, 1000)

                        } else if (likeTitleText && likeTitleText != "喜欢 0" && likeTitleText != "喜欢") {
                            //用户自己有喜欢的内容
                            echo("开始看用户喜欢的视频");
                            maxVideoReadCount = 1 + parseInt(Math.random() * 3);
                            var _location = getProfileTabbarLike(profileJson);
                            var _location_video = getProfileTabbarVideo(profileJson);
                            if (!_location || !_location_video) {
                                //没有获取到Tabbar
                                if (parseInt(Math.random() * 100) < VUE_APP.config.followPercent) {
                                    var _location = getFollowButton(profileJson);
                                    if (_location) {
                                        echo("正在关注当前用户");
                                        exec("adb shell input tap " + _location.x + " " + _location.y);
                                    }
                                }
                                echo("正在返回列表");
                                exec("adb shell input keyevent 4");
                                nowIndex++;
                                setTimeout(() => {
                                    openProfileTask();
                                }, 2000);
                                return;
                            }
                            //先切换到作品tabbar
                            exec("adb shell input tap " + _location.x + " " + _location.y);
                            setTimeout(() => {
                                //往下100 点视频 播放
                                exec("adb shell input tap " + _location_video.x + " " + (_location_video.y + 100));
                                hasBeenReadedCount = 1;
                                echo("正在看第" + hasBeenReadedCount + "个喜欢的视频");
                                //开始播放视频
                                playNextVideo(() => {
                                    echo("所有作品查看完毕");
                                    exec("adb shell input keyevent 4");
                                    echo("返回个人主页");
                                    setTimeout(() => {
                                        if (parseInt(Math.random() * 100) < VUE_APP.config.followPercent) {
                                            var _location = getFollowButton(profileJson);
                                            if (_location) {
                                                echo("正在关注当前用户");
                                                exec("adb shell input tap " + _location.x + " " + _location.y);
                                            }
                                        }
                                        echo("正在返回列表");
                                        exec("adb shell input keyevent 4");
                                        nowIndex++;
                                        setTimeout(() => {
                                            openProfileTask();
                                        }, 2000);
                                    }, 1000);
                                });
                            }, 1000)
                        } else {
                            echo("这可能是个私密帐号，不做任何处理");
                            echo("正在返回列表");
                            exec("adb shell input keyevent 4");
                            nowIndex++;
                            setTimeout(() => {
                                openProfileTask();
                            }, 2000);
                        }
                    } else {
                        if (parseInt(Math.random() * 100) < VUE_APP.config.followPercent) {
                            var _location = getFollowButton(profileJson);
                            if (_location) {
                                echo("正在关注当前用户");
                                exec("adb shell input tap " + _location.x + " " + _location.y);
                            }
                        }
                        echo("正在返回列表");
                        exec("adb shell input keyevent 4");
                        nowIndex++;
                        setTimeout(() => {
                            openProfileTask();
                        }, 2000);
                    }
                }, 3000);
            }
        }
        function getFansHeadPostionList(_json) {
            var _temp = JSON.stringify(_json).match(/.*?"_text":".*?关注.*?","_resource-id":"com.ss.android.ugc.aweme:id.*?"_bounds":"(.*?)"/g);
            var _fansPositionList = [];
            for (var _index in _temp) {
                if (_temp[_index].search('_text":"关注"') == -1) {
                    continue;
                }
                var _item = _temp[_index].match(/.*?关注.*?_bounds":"(.*?)"/);
                _fansPositionList.push({
                    x: parseInt((parseInt(_item[1].match(/[\d]+/g)[2])) / 2),
                    y: parseInt((parseInt(_item[1].match(/[\d]+/g)[3]) + parseInt(_item[1].match(/[\d]+/g)[1])) / 2),
                });
            }
            return _fansPositionList;
        }
        function getProfileTabbarLikeText(_profileJson) {
            var _temp = JSON.stringify(_profileJson).match(/android.support.v7.app.ActionBar\$Tab".*?"_text":"(喜欢.*?)","_resource-id":"android:id\//);
            if (!_temp) {
                return false;
            }
            return _temp.length > 1 ? _temp[1] : false;
        }
        function getProfileTabbarLike(_profileJson) {
            var _temp = JSON.stringify(_profileJson).match(/"_text":"喜欢.*?","_bounds":"(.*?)"/)
            if (!_temp) {
                return false;
            }
            if (_temp.length < 2) {
                return false;
            }
            var locationArray = _temp[1].match(/[\d]+/g);
            return {
                x: parseInt((parseInt(locationArray[0]) + parseInt(locationArray[2])) / 2),
                y: parseInt((parseInt(locationArray[1]) + parseInt(locationArray[3])) / 2)
            };
        }
        function getProfileTabbarVideo(_profileJson) {
            var _temp = JSON.stringify(_profileJson).match(/"_text":"作品.*?","_bounds":"(.*?)"/)
            if (!_temp) {
                return false;
            }
            if (_temp.length < 2) {
                return false;
            }
            var locationArray = _temp[1].match(/[\d]+/g);
            return {
                x: parseInt((parseInt(locationArray[0]) + parseInt(locationArray[2])) / 2),
                y: parseInt((parseInt(locationArray[1]) + parseInt(locationArray[3])) / 2)
            };
        }
        function getProfileTabbarVideoText(_profileJson) {
            var _temp = JSON.stringify(_profileJson).match(/_text":"(作品.*?)","_resource-id":"android:id\/text/);
            if (!_temp) {
                return false;
            }
            return _temp.length > 2 ? _temp[1] : false;
        }
        function getThePageLayout() {
            exec("adb shell rm -rf /data/local/tmp/uidump.xml");
            exec("adb shell uiautomator dump /data/local/tmp/uidump.xml");
            exec("adb pull /data/local/tmp/uidump.xml");
            var xml = fs.readFileSync("./uidump.xml", 'utf-8');
            var x2js = new X2JS();
            var json = x2js.xml_str2json(xml);
            // console.log(JSON.stringify(json));
            return json;
        }
        function getFollowButton(layoutJson) {
            if (JSON.stringify(layoutJson).search("取消关注") != -1 || JSON.stringify(layoutJson).search("请求") != -1) {
                //包含取消关注按钮
                echo("貌似已经关注过，无需操作");
                return false;
            }
            var _temp = JSON.stringify(layoutJson).match(/关注.*?android.widget.Button.*?_bounds":"(.*?)"/);
            if (!_temp) {
                return false;
            }
            if (_temp.length < 2) {
                return false;
            }
            var locationArray = _temp[1].match(/[\d]+/g);
            return {
                x: parseInt((parseInt(locationArray[0]) + parseInt(locationArray[2])) / 2),
                y: parseInt((parseInt(locationArray[1]) + parseInt(locationArray[3])) / 2)
            };
        }
        var maxVideoReadCount = 5;
        var hasBeenReadedCount = 0;
        function playNextVideo(callback) {
            if (!VUE_APP.status.isRunning) {
                return;
            }
            setTimeout(() => {
                if (hasBeenReadedCount > maxVideoReadCount) {
                    //不再播放视频
                    callback();
                } else {
                    if (parseInt(Math.random() * 100) < VUE_APP.config.likePercent) {
                        //判断是否自动点赞
                        echo("正在给视频点赞");
                        exec("adb shell input tap 990 1020");
                        setTimeout(() => {
                            if (parseInt(Math.random() * 100) < VUE_APP.config.commentPercent) {
                                //判断是否自动评论
                                echo("正在给视频评论");
                                exec("adb shell input tap 200 1960");
                                setTimeout(() => {
                                    var text4input = commentList[parseInt(Math.random() * commentList.length)];
                                    if (!text4input) {
                                        text4input = "哎哟不错这个屌";
                                    }
                                    exec("adb shell am broadcast -a ADB_INPUT_TEXT --es msg '" + text4input + "'");
                                    setTimeout(() => {
                                        exec("adb shell input tap 1000 1670");
                                        setTimeout(() => {
                                            exec("adb shell input swipe 500 1200 500 700 300");
                                            hasBeenReadedCount++;
                                            echo("正在看第" + hasBeenReadedCount + "个作品");
                                            playNextVideo(callback);
                                        }, 1000);
                                    }, 1000);
                                }, 2000);
                            } else {
                                exec("adb shell input swipe 500 1200 500 700 300");
                                hasBeenReadedCount++;
                                echo("正在看第" + hasBeenReadedCount + "个作品");
                                playNextVideo(callback);
                            }
                        }, 2000);
                    } else {
                        if (parseInt(Math.random() * 100) < VUE_APP.config.commentPercent) {
                            //判断是否自动评论
                            echo("正在给视频评论");
                            exec("adb shell input tap 200 1960");
                            setTimeout(() => {
                                var text4input = commentList[parseInt(Math.random() * commentList.length)];
                                if (!text4input) {
                                    text4input = "哎哟不错这个屌";
                                }
                                exec("adb shell am broadcast -a ADB_INPUT_TEXT --es msg '" + text4input + "'");
                                setTimeout(() => {
                                    exec("adb shell input tap 1000 1670");
                                    setTimeout(() => {
                                        exec("adb shell input swipe 500 1200 500 700 300");
                                        hasBeenReadedCount++;
                                        echo("正在看第" + hasBeenReadedCount + "个作品");
                                        playNextVideo(callback);
                                    }, 1000);
                                }, 1000);
                            }, 2000);
                        } else {
                            exec("adb shell input swipe 500 1200 500 700 300");
                            hasBeenReadedCount++;
                            echo("正在看第" + hasBeenReadedCount + "个作品");
                            playNextVideo(callback);
                        }
                    }
                }
            }, 1000 + parseInt(7000 * Math.random()));
        }
        var isDebug = true;
        function echo(msg, color = "#000", fontSize = "14") {
            if (isDebug) {
                console.log("%c " + msg, "font-size:" + fontSize + "px;color:" + color + ";font-weight:bold;font-family:consolas");
            }
        }
    </script>
</body>

</html>